package com.example.wasaimovie.Controller;

import com.alipay.api.AlipayApiException;
import com.example.wasaimovie.Annotation.DisableBaseResponse;
import com.example.wasaimovie.Model.entity.AlipayBean;
import com.example.wasaimovie.Service.PayService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
@RequestMapping("/ali")
public class AlipayController {
    /**日志对象*/
    private static final Logger logger = LoggerFactory.getLogger(OrderController.class);

    @Autowired
    private PayService payService;

    @RequestMapping("/pay")
    @ResponseBody
    @DisableBaseResponse
    public String alipay(String outTradeNo, String subject, String totalAmount) throws AlipayApiException {
        logger.info("商户订单号为{},订单名称为{},付款金额为{}", outTradeNo, subject, totalAmount);
        AlipayBean alipayBean = new AlipayBean();
        alipayBean.setOut_trade_no(outTradeNo);
        alipayBean.setSubject(subject);
        alipayBean.setTotal_amount(totalAmount);
        return payService.aliPay(alipayBean);
    }

    @RequestMapping("/success")
    @ResponseBody
    @DisableBaseResponse
    public String success(){
        return "交易成功！";
    }

    @RequestMapping(value = "/index")
    @DisableBaseResponse
    public String payCoin() {
        return "zfindex.html";
    }
}
